//
//  OUserRegLogic.m
//  soccer
//
//  Created by 上官千城 on 15/9/18.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "OUserRegLogic.h"
#import "ONet.h"


@implementation OUserRegLogic

/*
-(instancetype)initWithCallBack:(SEL)callBack
{
    return [super initWithName:@"OUserRegister" callBack:callBack];
}
*/

-(instancetype) initWithCallBack:(SEL)callBack for:(NSObject *)recvObjc
{
    return [super initWithName:@"OUserRegister" recvObjc:recvObjc callBack:callBack];
}
-(void) request
{
    NSDictionary* params = @{
        @"account":self.account,
        @"pwd":self.pwd,
        @"phone":self.phone,
        @"productId":self.protuctId
    };
    [self send:params];
}


-(void) run:(NSData *)data erc:(NSInteger)erc
{
    NSLog(@"regERC = %ld",erc);
    if (erc != SUCC) {
        if (erc == USER_EXIST) {
            //用户名已存在
            UIAlertView *sameName = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用户名已存在" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [sameName show];
        }
        else{
            //系统异常
            UIAlertView *Abnormal = [[UIAlertView alloc]initWithTitle:@"提示" message:@"系统异常APP 即将退出" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [Abnormal show];
            
        }
        return;
    }
    
    NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
//    self.token = [dic objectForKey:@"token"];
//    self.sign = [dic objectForKey:@"sign"];
    
    NSLog(@"reg succ data=%@",dic);
    //TODO:succ logic process;
   /* if (muDelegate) {
        muDelegate(self);
    }*/
    [self mu];
}

@end
